import Vue from 'vue';
import Vuex from 'vuex';
import createPersistedState from "vuex-persistedstate";

import present from './present'
import {
    Random_users,
    Random_lottery
} from "@/utils/lottery";
Vue.use(Vuex);

const state = {
    users: [],
    status: 0,
    presents: present.present,
    num: 10
}

const mutations = {
    getLotteryUsers(state, num) {
        return Random_lottery(state.users, num);
    },
    add(state) {
        return state.status++;
    },
    getUsers(state, array) {
        state.users = array;
    },
    getPresents(state, array) {
        state.presents = array;
    },
    getNum(state, num) {
        state.num = num;
    },
}

const getters = {
    getRandomUsers(state) {
        return Random_users(state.users);
    }
}

export default new Vuex.Store({
    state,
    mutations,
    getters,
    plugins: [createPersistedState()]
})